/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-07-13
 * Time: 11:34
 */
public class test2 {
    public int LastRemaining_Solution (int n, int m) {
        int f=0;
        for(int i=2;i<=n;i++){
            f =(f+m)%i;
        }
        return f;
    }
}
